<!--
 * @Author: your name
 * @Date: 2021-05-07 15:19:53
 * @LastEditTime: 2021-05-07 16:23:22
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \vue01d:\HTML001\布局小技巧\练习\解决data中渲染.html
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <div v-for="item of arr">{{item}}</div>
      <div v-for="item of obj">{{item}}</div>
      <div v-for="item of people">{{item}}</div>
      <button @click="fun">点击</button>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
      new Vue({
        el: "#app",
        data() {
          return {
            arr: [1, 2, 2, 3, 4],
            obj: { name: "lisi", age: 78 },
            people: [
              { name: "张三", age: 15, sex: "男" },
              { name: "李四", age: 97, sex: "男" },
              { name: "麻子", age: 66, sex: "男" },
              { name: "小红", age: 18, sex: "女" },
            ],
          };
        },
        methods: {
          fun() {
            // 两种方法，一个数组自带的，一个vue提供的
            // this.arr.splice(0,1,"w")
            this.$set(this.arr, 0, "e");

            // this.$set(this.arr,"key","e")修改对象中的要加''
            // 会返回一个新的数组，我们再从新把他赋值回去,改成中括号可以修改数组
            // this.obj = Object.assign({}, this.obj, {
            //   name: "dsa",
            //   age: 234,
            // });
            // 删除对象中的属性
            // this.$delete(this.obj, "age")
            this.people.forEach((item) => {
              this.$set(item, "hibby","打游戏");
            });
            this.people.forEach((item) => {
              this.$delete(item, "sex");
            });
            this.people.forEach((item) => {
              this.$set(item, "age",18);
            });
            
          },
        },
      });
    </script>
  </body>
</html>
